const fs = require('fs');
const path = require('path');

fs.readFile(path.resolve(__dirname,'name123.txt'),'utf8',function(err,data){
  console.log('错误');
  console.log(err);
});
console.log(222);
/*
222
错误
[Error: ENOENT: no such file or directory, open 'F:\js_workplace\tutorial\node_tutorial\3.generator\name123.txt'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'F:\\js_workplace\\tutorial\\node_tutorial\\3.generator\\name123.txt'
}
*/

function read(filepath){
  return new Promise((resolve, reject) => {
    fs.readFile(filepath,'utf8',function(err,data){
      if(err) return reject(err);
      resolve(data);
    });
  });
}
